package com.forum.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.forum.annotation.IgnoreAuth;
import com.forum.entity.DataevaluationEntity;
import com.forum.entity.PgdInformationEntity;
import com.forum.service.DataevaluationService;
import com.forum.utils.MPUtil;
import com.forum.utils.PageUtils;
import com.forum.utils.R;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.Map;

/**
 * <p>
 * 资料评论表 前端控制器
 * </p>
 *
 * @author LiangFeng
 * @since 2023-12-26
 */
@RestController
@RequestMapping("/dataevaluation")
@Slf4j
@Api(tags = "资料评论表控制器")
public class DataevaluationController {

    @Autowired
    private DataevaluationService dataevaluationService;


    @IgnoreAuth
    @GetMapping("/list")
    @SuppressWarnings("unchecked")
    public R list(@RequestParam Map<String,Object> params, DataevaluationEntity dataevaluationEntity,
                  HttpServletRequest request){

        EntityWrapper<DataevaluationEntity> entityEntityWrapper = new EntityWrapper<DataevaluationEntity>();
        PageUtils pageUtils = dataevaluationService.queryPage(params,
                MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(entityEntityWrapper, dataevaluationEntity), params), params));
        return R.ok().put("data",pageUtils);
    }

    @PostMapping("/add")
    public R add(@RequestBody DataevaluationEntity dataevaluationEntity,
                 HttpServletRequest request){
        dataevaluationEntity.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
        log.info("相关返回参数：{}",dataevaluationEntity);
        dataevaluationService.insert(dataevaluationEntity);
        return R.ok();
    }
}
